import {
	defineStore
} from 'pinia'
import {
	ref
} from 'vue'

import {
	staticRoutes
} from '../router/staticRoutes.js'


export const useStore = defineStore('main', () => {
	const menu = ref(staticRoutes)
	const token = ref()
	const userName = ref()
	const getRoutes = (routes) => {

		return routes
			.filter(route => !(route.meta && route.meta.show === 1))
			.map(route => {
				if (route.children) {
					route.children = getRoutes(route.children);
				}
				return route
			})
	}

	const clearData = () => {
		menu.value = staticRoutes
		token.value = null;
		userName.value = null;
	}

	return {
		menu,
		token,
		getRoutes,
		userName,
		clearData
	}
})